package io.renren.modules.user.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.modules.combat.entity.TFightPeopleEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.user.entity.TPeopleChangeTemporaryEntity;
import io.renren.modules.user.service.TPeopleChangeTemporaryService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-09-20 18:44:49
 */
@RestController
@RequestMapping("/tpeoplechangetemporary")
public class TPeopleChangeTemporaryController {
    @Autowired
    private TPeopleChangeTemporaryService tPeopleChangeTemporaryService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("user:tpeoplechangetemporary:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tPeopleChangeTemporaryService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("user:tpeoplechangetemporary:info")
    public R info(@PathVariable("id") Integer id){
		TPeopleChangeTemporaryEntity tPeopleChangeTemporary = tPeopleChangeTemporaryService.getById(id);

        return R.ok().put("tPeopleChangeTemporary", tPeopleChangeTemporary);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("user:tpeoplechangetemporary:save")
    public R save(@RequestBody TPeopleChangeTemporaryEntity tPeopleChangeTemporary){
        tPeopleChangeTemporaryService.saveBatch(tPeopleChangeTemporary.getList());

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("user:tpeoplechangetemporary:update")
    public R update(@RequestBody TPeopleChangeTemporaryEntity tPeopleChangeTemporary){
		tPeopleChangeTemporaryService.updateById(tPeopleChangeTemporary);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("user:tpeoplechangetemporary:delete")
    public R delete(@RequestBody Integer[] ids){
		tPeopleChangeTemporaryService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }


    /**
     * 列表
     */
    @RequestMapping("/getTPeopleTemporary")
    //@RequiresPermissions("user:tpeoplechangetemporary:getTPeopleTemporary")
    public R list(@RequestBody TPeopleChangeTemporaryEntity tPeopleChangeTemporary){
        List<TPeopleChangeTemporaryEntity> page = tPeopleChangeTemporaryService.getTPeopleTemporary(tPeopleChangeTemporary);
        return R.ok().put("page", page);
    }
    /**
     * 删除
     */
    @RequestMapping("/del")
    //@RequiresPermissions("user:tpeoplechangetemporary:delete")
    public R del(){
        tPeopleChangeTemporaryService.del();
        return R.ok();
    }


    /**
     * update
     */
    @RequestMapping("/updateState")
    //@RequiresPermissions("user:tpeoplechangetemporary:update")
    public R updateState(@RequestBody TPeopleChangeTemporaryEntity tPeopleChangeTemporary){
        Integer num=tPeopleChangeTemporary.getUpdateList().size();
        for(int i=0;i<num;i++){
            Integer sum= tPeopleChangeTemporary.getUpdateList().get(i).getId();
            TPeopleChangeTemporaryEntity a=new TPeopleChangeTemporaryEntity();
            a.setId(sum);
            tPeopleChangeTemporaryService.updateState(a);
        }
        return R.ok();
    }

    /**
     * 列表
     */
    @RequestMapping("/getTPeople")
    //@RequiresPermissions("user:tpeoplechangetemporary:getTPeople")
    public R getTPeople(@RequestBody TPeopleChangeTemporaryEntity tPeopleChangeTemporary){
        List<TPeopleChangeTemporaryEntity> page = tPeopleChangeTemporaryService.getTPeople(tPeopleChangeTemporary);
        return R.ok().put("page", page);
    }
}
